package com.lc.zpyh.ui.activity.home;

import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.lc.zpyh.R;
import com.lc.zpyh.app.AppActivity;
import com.lc.zpyh.http.glide.GlideApp;
import com.lc.zpyh.http.request.SelectMyRefereesApi;
import com.lc.zpyh.http.response.MyRefereesBean;
import com.lc.zpyh.other.IntentKey;
import com.lc.zpyh.util.SPUtil;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class MyFansActivity extends AppActivity {
    List<String> dataBeanList=new ArrayList<>();

    private BaseQuickAdapter<MyRefereesBean.ListBean.MyRefereessBean, BaseViewHolder> adapter;
    @BindView(R.id.my_pic)
    ImageView myPic;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_invite_num)
    TextView tvInviteNum;
    @BindView(R.id.rv_invite)
    RecyclerView rvInvite;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_myfans;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);

        selectMyReferees("1");


    }

    private void selectMyReferees(String page) {
        EasyHttp.post(this)
                .api(new SelectMyRefereesApi().setUserid(SPUtil.get(MyFansActivity.this, IntentKey.USERID,"")).setPageNum(page).setPageSize("999")).request(new HttpCallback<MyRefereesBean>(this) {

            @Override
            public void onSucceed(MyRefereesBean data) {

                adapter = new BaseQuickAdapter<MyRefereesBean.ListBean.MyRefereessBean, BaseViewHolder>
                        (R.layout.item_invite,data.getList().getMyRefereess()) {

                    @Override
                    protected void convert(BaseViewHolder baseViewHolder,MyRefereesBean.ListBean.MyRefereessBean dataBean) {
                        baseViewHolder.setText(R.id.tv_name,dataBean.getName());
                        baseViewHolder.setText(R.id.tv_date,"注册时间："+dataBean.getAddtime().substring(0,10));
                        GlideApp.with(MyFansActivity.this)
                                .load(IntentKey.CAR_IMAGE+dataBean.getImg())
                                .circleCrop()
                                .into((ImageView) baseViewHolder.getView(R.id.img_pic));
                    }

                };
                rvInvite.setAdapter(adapter);
                GlideApp.with(MyFansActivity.this)
                        .load(IntentKey.CAR_IMAGE+data.getList().getUser().getImg())
                        .circleCrop()
                        .into(myPic);
                tvName.setText(data.getList().getUser().getName());
                tvInviteNum.setText("已邀请"+data.getList().getUser().getCount()+"人");
            }
            @Override
            public void onFail(Exception e) {
                super.onFail(e);

            }
        });

    }
}
